package cn.ibizlab.odoo.core.odoo_event.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ievent_registration;
import cn.ibizlab.odoo.core.odoo_event.domain.Event_registration;
import cn.ibizlab.odoo.core.odoo_event.filter.Event_registrationSearchContext;
import cn.ibizlab.odoo.core.odoo_event.service.IEvent_registrationService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[事件记录] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Event_registrationServiceImpl implements IEvent_registrationService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ievent_registrationClientService event_registrationClientService;

    @Override
    public boolean create(Event_registration event_registration) {
        boolean bOk = false ;
        Ievent_registration clientModel = this.convert2Model(event_registration,null);
        event_registrationClientService.create(clientModel) ;
        this.convert2Domain(clientModel,event_registration);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Event_registration> event_registrations, int batchSize) {

                        //event_registrationClientService.createBatch(event_registrations,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //event_registrationClientService.removeBatch(event_registrations) ;

    }

    @Override
    public void updateBatch(List<Event_registration> event_registrations, int batchSize) {

        //event_registrationClientService.updateBatch(event_registrations,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ievent_registration clientModel = event_registrationClientService.createModel();
        clientModel.setId(id);
        event_registrationClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Event_registration event_registration) {
        boolean bOk = false ;
        Ievent_registration clientModel = this.convert2Model(event_registration,null);
        event_registrationClientService.update(clientModel) ;
        this.convert2Domain(clientModel,event_registration) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Event_registration get(Integer id) {
        Ievent_registration clientModel = event_registrationClientService.createModel();
        clientModel.setId(id);
        event_registrationClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Event_registration get(Event_registration event_registration) {
        Event_registration retevent_registration = this.get(event_registration.getId()) ;
    	BeanCopier copier=BeanCopier.create(retevent_registration.getClass(), event_registration.getClass(), false);
        copier.copy(retevent_registration, event_registration, null);
        return event_registration ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Event_registration> searchDefault(Event_registrationSearchContext context) {
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据活动入场券查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_event_ticket(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据活动查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_event(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_company(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_partner(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_create(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_write(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据销售订单行查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_sale_order_line(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据销售订单查询
     */
    @Override
    public Page<Event_registration> selectByOdoo_sale_order(Integer id){
        Event_registrationSearchContext context = new Event_registrationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_registration> list = new ArrayList<Event_registration>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_registration> clientModelList = event_registrationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_registration clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_registration>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ievent_registration convert2Model(Event_registration domain , Ievent_registration model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = event_registrationClientService.createModel() ;
        }

         if(domain.getMessage_main_attachment_idDirtyFlag())
            model.setMessage_main_attachment_id(domain.getMessage_main_attachment_id());
         if(domain.getPhoneDirtyFlag())
            model.setPhone(domain.getPhone());
         if(domain.getDate_openDirtyFlag())
            model.setDate_open(domain.getDate_open());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getMessage_unreadDirtyFlag())
            model.setMessage_unread(domain.getMessage_unread());
         if(domain.getMessage_follower_idsDirtyFlag())
            model.setMessage_follower_ids(domain.getMessage_follower_ids());
         if(domain.getMessage_is_followerDirtyFlag())
            model.setMessage_is_follower(domain.getMessage_is_follower());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getOriginDirtyFlag())
            model.setOrigin(domain.getOrigin());
         if(domain.getMessage_channel_idsDirtyFlag())
            model.setMessage_channel_ids(domain.getMessage_channel_ids());
         if(domain.getMessage_has_error_counterDirtyFlag())
            model.setMessage_has_error_counter(domain.getMessage_has_error_counter());
         if(domain.getMessage_partner_idsDirtyFlag())
            model.setMessage_partner_ids(domain.getMessage_partner_ids());
         if(domain.getMessage_attachment_countDirtyFlag())
            model.setMessage_attachment_count(domain.getMessage_attachment_count());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getEmailDirtyFlag())
            model.setEmail(domain.getEmail());
         if(domain.getMessage_has_errorDirtyFlag())
            model.setMessage_has_error(domain.getMessage_has_error());
         if(domain.getMessage_unread_counterDirtyFlag())
            model.setMessage_unread_counter(domain.getMessage_unread_counter());
         if(domain.getMessage_needactionDirtyFlag())
            model.setMessage_needaction(domain.getMessage_needaction());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getMessage_needaction_counterDirtyFlag())
            model.setMessage_needaction_counter(domain.getMessage_needaction_counter());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getDate_closedDirtyFlag())
            model.setDate_closed(domain.getDate_closed());
         if(domain.getMessage_idsDirtyFlag())
            model.setMessage_ids(domain.getMessage_ids());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWebsite_message_idsDirtyFlag())
            model.setWebsite_message_ids(domain.getWebsite_message_ids());
         if(domain.getEvent_begin_dateDirtyFlag())
            model.setEvent_begin_date(domain.getEvent_begin_date());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getSale_order_id_textDirtyFlag())
            model.setSale_order_id_text(domain.getSale_order_id_text());
         if(domain.getEvent_end_dateDirtyFlag())
            model.setEvent_end_date(domain.getEvent_end_date());
         if(domain.getSale_order_line_id_textDirtyFlag())
            model.setSale_order_line_id_text(domain.getSale_order_line_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getEvent_ticket_id_textDirtyFlag())
            model.setEvent_ticket_id_text(domain.getEvent_ticket_id_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getEvent_id_textDirtyFlag())
            model.setEvent_id_text(domain.getEvent_id_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getEvent_idDirtyFlag())
            model.setEvent_id(domain.getEvent_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getSale_order_line_idDirtyFlag())
            model.setSale_order_line_id(domain.getSale_order_line_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getEvent_ticket_idDirtyFlag())
            model.setEvent_ticket_id(domain.getEvent_ticket_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getSale_order_idDirtyFlag())
            model.setSale_order_id(domain.getSale_order_id());
        return model ;
    }

    public Event_registration convert2Domain( Ievent_registration model ,Event_registration domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Event_registration();
        }

        if(model.getMessage_main_attachment_idDirtyFlag())
            domain.setMessage_main_attachment_id(model.getMessage_main_attachment_id());
        if(model.getPhoneDirtyFlag())
            domain.setPhone(model.getPhone());
        if(model.getDate_openDirtyFlag())
            domain.setDate_open(model.getDate_open());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getMessage_unreadDirtyFlag())
            domain.setMessage_unread(model.getMessage_unread());
        if(model.getMessage_follower_idsDirtyFlag())
            domain.setMessage_follower_ids(model.getMessage_follower_ids());
        if(model.getMessage_is_followerDirtyFlag())
            domain.setMessage_is_follower(model.getMessage_is_follower());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getOriginDirtyFlag())
            domain.setOrigin(model.getOrigin());
        if(model.getMessage_channel_idsDirtyFlag())
            domain.setMessage_channel_ids(model.getMessage_channel_ids());
        if(model.getMessage_has_error_counterDirtyFlag())
            domain.setMessage_has_error_counter(model.getMessage_has_error_counter());
        if(model.getMessage_partner_idsDirtyFlag())
            domain.setMessage_partner_ids(model.getMessage_partner_ids());
        if(model.getMessage_attachment_countDirtyFlag())
            domain.setMessage_attachment_count(model.getMessage_attachment_count());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getEmailDirtyFlag())
            domain.setEmail(model.getEmail());
        if(model.getMessage_has_errorDirtyFlag())
            domain.setMessage_has_error(model.getMessage_has_error());
        if(model.getMessage_unread_counterDirtyFlag())
            domain.setMessage_unread_counter(model.getMessage_unread_counter());
        if(model.getMessage_needactionDirtyFlag())
            domain.setMessage_needaction(model.getMessage_needaction());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getMessage_needaction_counterDirtyFlag())
            domain.setMessage_needaction_counter(model.getMessage_needaction_counter());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDate_closedDirtyFlag())
            domain.setDate_closed(model.getDate_closed());
        if(model.getMessage_idsDirtyFlag())
            domain.setMessage_ids(model.getMessage_ids());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWebsite_message_idsDirtyFlag())
            domain.setWebsite_message_ids(model.getWebsite_message_ids());
        if(model.getEvent_begin_dateDirtyFlag())
            domain.setEvent_begin_date(model.getEvent_begin_date());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getSale_order_id_textDirtyFlag())
            domain.setSale_order_id_text(model.getSale_order_id_text());
        if(model.getEvent_end_dateDirtyFlag())
            domain.setEvent_end_date(model.getEvent_end_date());
        if(model.getSale_order_line_id_textDirtyFlag())
            domain.setSale_order_line_id_text(model.getSale_order_line_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getEvent_ticket_id_textDirtyFlag())
            domain.setEvent_ticket_id_text(model.getEvent_ticket_id_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getEvent_id_textDirtyFlag())
            domain.setEvent_id_text(model.getEvent_id_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getEvent_idDirtyFlag())
            domain.setEvent_id(model.getEvent_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getSale_order_line_idDirtyFlag())
            domain.setSale_order_line_id(model.getSale_order_line_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getEvent_ticket_idDirtyFlag())
            domain.setEvent_ticket_id(model.getEvent_ticket_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getSale_order_idDirtyFlag())
            domain.setSale_order_id(model.getSale_order_id());
        return domain ;
    }


}
